*** REPLICATION DOCUMENT FOR BAS and STONE ISQ
* TABLE 2 Marginal Effects
* run in Stata 18
* set working directory to the replication folder

use "BasStoneReplication.dta", clear


* This llik normalizes UV1 = 0 uI2=0
capture program drop partobs2_lf
program define partobs2_lf
        version 8.0
	args 	lnf uV2 uV3 uI3	
	tempvar pV pI 
	qui gen double `pI' = norm((`uI3')/sqrt(2))
	qui gen double `pV' = norm((`pI'*`uV3' + (1-`pI')*`uV2')/sqrt(2))

	qui replace `lnf' = ln(`pV') + ln(`pI')   if $ML_y1 == 1
	qui replace `lnf' = ln(1-`pV'*`pI') if $ML_y1 == 0
	qui replace `lnf' = ln(`pV') + ln(1-`pI') if $ML_y1 == 2
	qui replace `lnf' = ln(1-`pV') if $ML_y1 == 3	
end




set more off
set seed 1234567

ml model lf partobs2_lf (uV2:stepdown3 = catr mil mtnest elf lnten idealpointdi) (uV3:stepdown3 =  interconfinc intraconfinc hostlev_mn gdppcgr gdppc totalnumberofcrisis2) (uI3: stepdown3 = mil idealpointdi upopr perspercap2 poltr pcatr lagout gdppc)
matrix inits = (3.249653,  2.372404, -.0104462, -1.129891, -7.330102,  2.317568,   55.6942, -1.557992,  .0550265,  .4624153, -7.680818, -.0256894,   .205055, -.0709777, -.8286697,  .4616707,   .938277,  .1427571, -.7341128, -2.035021,  1.352735,  .1079354, -.6019921)
ml init inits, copy skip
*ml search, r(5000)
ml maximize, difficult iterate(200)



gen samprep = e(sample)

sum mil idealpointdi upopr perspercap2 poltr pcatr lagout gdppc if samprep==1
centile mil idealpointdi upopr perspercap2 poltr pcatr lagout gdppc if samprep==1, centile(5 95)

expand 2 in 1
replace mil= 0 in 10939
replace idealpointdistance = 2 in 10939
replace upopr= .27 in 10939
replace perspercap2= .59 in 10939
replace poltrqnew= .58 in 10939
replace pcatr= .33 in 10939
replace lagout= 0 in 10939
replace gdppc = 10.66 in 10939

capture drop inc_mar_mil* imildo imilup
predictnl inc_mar_mil_base = normal(xb(#3)/sqrt(2))
predictnl inc_mar_mil = normal((xb(#3) +_b[uI3:mil]) /sqrt(2)) - normal(xb(#3)/sqrt(2)), ci(imildo imilup)

*replace idealpointdistance = .25 in 10939
capture drop inc_mar_ide* iidedo iideup
predictnl inc_mar_ide_base = normal(xb(#3)/sqrt(2))
predictnl inc_mar_ide = normal((xb(#3) +(1.08)*_b[uI3:idealpointdistance]) /sqrt(2)) - normal(xb(#3)/sqrt(2)), ci(iidedo iideup)

*replace idealpointdistance = 2 in 10939
*replace poltrqnew= .05 in 10939
capture drop inc_mar_pol* ipoldo ipolup
predictnl inc_mar_pol_base = normal(xb(#3)/sqrt(2))
predictnl inc_mar_pol = normal((xb(#3) +(.61)*_b[uI3:poltrqnew]) /sqrt(2)) - normal(xb(#3)/sqrt(2)), ci(ipoldo ipolup)

*replace poltrqnew= .58 in 10939
*replace pcatr= 0 in 10939
capture drop inc_mar_cat* icatdo icatup
predictnl inc_mar_cat_base = normal(xb(#3)/sqrt(2))
predictnl inc_mar_cat = normal((xb(#3) +.30*_b[uI3:pcatr]) /sqrt(2)) - normal(xb(#3)/sqrt(2)), ci(icatdo icatup)

*replace pcatr= .33 in 10939
*replace lagout= -1 in 10939
capture drop inc_mar_lag* ilagdo ilagup
predictnl inc_mar_lag_base = normal(xb(#3)/sqrt(2))
predictnl inc_mar_lag = normal((xb(#3) +(1)*_b[uI3:lagout]) /sqrt(2)) - normal(xb(#3)/sqrt(2)), ci(ilagdo ilagup)

*replace lagout= 0 in 10939
*replace gdppc = .73 in 10939
capture drop inc_mar_gdp* igdpdo igdpup
predictnl inc_mar_gdp_base = normal(xb(#3)/sqrt(2))
predictnl inc_mar_gdp = normal((xb(#3) +(9.74)*_b[uI3:gdppc]) /sqrt(2)) - normal(xb(#3)/sqrt(2)), ci(igdpdo igdpup)

sum inc_mar_mil_base - igdpup in 10939


**** THIS PRODUCES THE SECOND HALF OF TABLE 2 (STEP DOWN COLUMNS)

* Lagged Outcome
* baseline
sum inc_mar_lag_base in 10939
* marginal effect
sum  inc_mar_lag  in 10939
* confidence interval
sum  ilagdo ilagup  in 10939

* Military background
* baseline
sum inc_mar_mil_base in 10939
* marginal effect
sum  inc_mar_mil  in 10939
* confidence interval
sum  imildo imilup  in 10939

* Ideal Point Distance
* baseline
sum inc_mar_ide_base in 10939
* marginal effect
sum  inc_mar_ide  in 10939
* confidence interval
sum  iidedo iideup  in 10939

* GDP per capita
* baseline
sum inc_mar_gdp_base in 10939
* marginal effect
sum  inc_mar_gdp  in 10939
* confidence interval
sum  igdpdo igdpup  in 10939

* Perc CAT ratifier
* baseline
sum inc_mar_cat_base in 10939
* marginal effect
sum  inc_mar_cat  in 10939
* confidence interval
sum  icatdo icatup  in 10939

* Polarization
* baseline
sum inc_mar_pol_base in 10939
* marginal effect
sum  inc_mar_pol  in 10939
* confidence interval
sum  ipoldo ipolup  in 10939



capture drop in 10939

sum catr mtnest elf lnten interconfinc intraconfinc hostlev_mn gdppcgr totalnumberofcrisis2 mil idealpointdi upopr perspercap2 poltr pcatr lagout gdppc if samprep==1
centile catr mtnest elf lnten interconfinc intraconfinc hostlev_mn gdppcgr totalnumberofcrisis2 mil idealpointdi upopr perspercap2 poltr pcatr lagout gdppc if samprep==1, centile(5 95)

expand 2 in 1
replace mil= 0 in 10939
replace idealpointdistance = 2 in 10939
replace upopr= .27 in 10939
replace perspercap2= .59 in 10939
replace poltrqnew= .58 in 10939
replace pcatr= .33 in 10939
replace lagout= 0 in 10939
replace gdppc = 10.66 in 10939

replace catr = 0 in 10939
replace mtnest = 17.04 in 10939
replace elf = .34 in 10939
replace lnten = 7.5 in 10939
replace interconfinc = 0 in 10939
replace intraconfinc = 0 in 10939
replace hostlev_mn = 0 in 10939
replace gdppcgr = .026 in 10939
replace totalnumberofcrisis2 = 0 in 10939


capture drop vot_mar_mil* vmildo vmilup
predictnl vot_mar_mil_base = normal((normal((xb(#3))/sqrt(2))*(xb(#2)) +(1-normal((xb(#3))/sqrt(2)))*xb(#1))/sqrt(2))
predictnl vot_mar_mil = normal((normal((xb(#3) + _b[uI3:mil])/sqrt(2))*(xb(#2)) +(1-normal((xb(#3) + _b[uI3:mil])/sqrt(2)))*(xb(#1) + _b[uV2:mil]))/sqrt(2)) - normal((normal((xb(#3))/sqrt(2))*(xb(#2)) +(1-normal((xb(#3))/sqrt(2)))*xb(#1))/sqrt(2)), ci(vmildo vmilup)

*replace idealpointdistance = .25 in 10939
capture drop vot_mar_ide* videdo videup
predictnl vot_mar_ide_base = normal((normal((xb(#3))/sqrt(2))*(xb(#2)) +(1-normal((xb(#3))/sqrt(2)))*xb(#1))/sqrt(2))
predictnl vot_mar_ide = normal((normal((xb(#3) + (1.08)*_b[uI3:idealpointdistance])/sqrt(2))*(xb(#2)) +(1-normal((xb(#3) + (1.08)*_b[uI3:idealpointdistance])/sqrt(2)))*(xb(#1) + (1.08)*_b[uV2:idealpointdistance]))/sqrt(2)) - normal((normal((xb(#3))/sqrt(2))*(xb(#2)) +(1-normal((xb(#3))/sqrt(2)))*xb(#1))/sqrt(2)), ci(videdo videup)

*replace idealpointdistance = 2 in 10939
*replace gdppc = .73 in 10939
capture drop vot_mar_gdp vot_mar_gdp_base vgdpdo vgdpup
predictnl vot_mar_gdp_base = normal((normal((xb(#3))/sqrt(2))*(xb(#2)) +(1-normal((xb(#3))/sqrt(2)))*xb(#1))/sqrt(2))
predictnl vot_mar_gdp = normal((normal((xb(#3) +(9.74)*_b[uI3:gdppc])/sqrt(2))*(xb(#2)+(9.74)*_b[uV3:gdppc]) +(1-normal((xb(#3) +(9.74)*_b[uI3:gdppc])/sqrt(2)))*(xb(#1)))/sqrt(2)) - normal((normal((xb(#3))/sqrt(2))*(xb(#2)) +(1-normal((xb(#3))/sqrt(2)))*xb(#1))/sqrt(2)), ci(vgdpdo vgdpup)

*replace gdppc = 10.66 in 10939
*replace gdppcgr = -.05 in 10939
capture drop vot_mar_gdpgr* vgdpgrdo vgdpgrup
predictnl vot_mar_gdpgr_base = normal((normal((xb(#3))/sqrt(2))*(xb(#2)) +(1-normal((xb(#3))/sqrt(2)))*xb(#1))/sqrt(2))
predictnl vot_mar_gdpgr = normal((normal((xb(#3))/sqrt(2))*(xb(#2)+(.063)*_b[uV3:gdppcgr]) +(1-normal((xb(#3))/sqrt(2)))*(xb(#1)))/sqrt(2)) - normal((normal((xb(#3))/sqrt(2))*(xb(#2)) +(1-normal((xb(#3))/sqrt(2)))*xb(#1))/sqrt(2)), ci(vgdpgrdo vgdpgrup)


*replace gdppcgr = .026 in 10939
capture drop vot_mar_tot* vtotdo vtotup
predictnl vot_mar_tot_base = normal((normal((xb(#3))/sqrt(2))*(xb(#2)) +(1-normal((xb(#3))/sqrt(2)))*xb(#1))/sqrt(2))
predictnl vot_mar_tot = normal((normal((xb(#3))/sqrt(2))*(xb(#2)+1*_b[uV3:totalnumberofcrisis2]) +(1-normal((xb(#3))/sqrt(2)))*(xb(#1)))/sqrt(2)) - normal((normal((xb(#3))/sqrt(2))*(xb(#2)) +(1-normal((xb(#3))/sqrt(2)))*xb(#1))/sqrt(2)), ci(vtotdo vtotup)

capture drop vot_mar_cat* vcatdo vcatup
predictnl vot_mar_cat_base = normal((normal((xb(#3))/sqrt(2))*(xb(#2)) +(1-normal((xb(#3))/sqrt(2)))*xb(#1))/sqrt(2))
predictnl vot_mar_cat = normal((normal((xb(#3))/sqrt(2))*(xb(#2)) +(1-normal((xb(#3))/sqrt(2)))*(xb(#1)+.5*_b[uV2:catr]))/sqrt(2)) - normal((normal((xb(#3))/sqrt(2))*(xb(#2)) +(1-normal((xb(#3))/sqrt(2)))*xb(#1))/sqrt(2)), ci(vcatdo vcatup)

capture drop vot_mar_lnt* vlntdo vlntup
predictnl vot_mar_lnt_base = normal((normal((xb(#3))/sqrt(2))*(xb(#2)) +(1-normal((xb(#3))/sqrt(2)))*xb(#1))/sqrt(2))
predictnl vot_mar_lnt = normal((normal((xb(#3))/sqrt(2))*(xb(#2)) +(1-normal((xb(#3))/sqrt(2)))*(xb(#1)+.21*_b[uV2:lnten]))/sqrt(2)) - normal((normal((xb(#3))/sqrt(2))*(xb(#2)) +(1-normal((xb(#3))/sqrt(2)))*xb(#1))/sqrt(2)), ci(vlntdo vlntup)

*replace interconfinc = 0 in 10939
capture drop vot_mar_con* vcondo vconup
predictnl vot_mar_con_base = normal((normal((xb(#3))/sqrt(2))*(xb(#2)) +(1-normal((xb(#3))/sqrt(2)))*xb(#1))/sqrt(2))
predictnl vot_mar_con = normal((normal((xb(#3))/sqrt(2))*(xb(#2) +_b[uV3:interconfinc]) +(1-normal((xb(#3))/sqrt(2)))*(xb(#1)))/sqrt(2)) - normal((normal((xb(#3))/sqrt(2))*(xb(#2)) +(1-normal((xb(#3))/sqrt(2)))*xb(#1))/sqrt(2)), ci(vcondo vconup)

*replace interconfinc = 1 in 10939
capture drop vot_mar_hos* vhosdo vhosup
predictnl vot_mar_hos_base = normal((normal((xb(#3))/sqrt(2))*(xb(#2)) +(1-normal((xb(#3))/sqrt(2)))*xb(#1))/sqrt(2))
predictnl vot_mar_hos = normal((normal((xb(#3))/sqrt(2))*(xb(#2) +_b[uV3:hostlev_mn]) +(1-normal((xb(#3))/sqrt(2)))*(xb(#1)))/sqrt(2)) - normal((normal((xb(#3))/sqrt(2))*(xb(#2)) +(1-normal((xb(#3))/sqrt(2)))*xb(#1))/sqrt(2)), ci(vhosdo vhosup)


sum vot_mar_mil_base - vhosup in 10939


**** THIS PRODUCES THE FIRST HALF OF TABLE 2 (REPLACE COLUMNS)


* Military background
* baseline
sum vot_mar_mil_base in 10939
* marginal effect
sum  vot_mar_mil  in 10939
* confidence interval
sum  vmildo vmilup  in 10939



* Ideal Point Distance
* baseline
sum vot_mar_ide_base in 10939
* marginal effect
sum  vot_mar_ide  in 10939
* confidence interval
sum  videdo videup  in 10939

* GDP per capita
* baseline
sum vot_mar_gdp_base in 10939
* marginal effect
sum  vot_mar_gdp  in 10939
* confidence interval
sum  vgdpdo vgdpup  in 10939

* GDP per capita growth
* baseline
sum vot_mar_gdpgr_base in 10939
* marginal effect
sum  vot_mar_gdpgr  in 10939
* confidence interval
sum  vgdpgrdo vgdpgrup  in 10939

* CAT ratifier
* baseline
sum vot_mar_cat_base in 10939
* marginal effect
sum  vot_mar_cat  in 10939
* confidence interval
sum  vcatdo vcatup  in 10939

* Ln of Tenure
* baseline
sum vot_mar_lnt_base in 10939
* marginal effect
sum  vot_mar_lnt  in 10939
* confidence interval
sum  vlntdo vlntup  in 10939

* Interstate MID
* baseline
sum vot_mar_con_base in 10939
* marginal effect
sum  vot_mar_con  in 10939
* confidence interval
sum  vcondo vconup  in 10939

* Hostility Level
* baseline
sum vot_mar_hos_base in 10939
* marginal effect
sum  vot_mar_hos  in 10939
* confidence interval
sum  vhosdo vhosup  in 10939

* Financial Crises
* baseline
sum vot_mar_tot_base in 10939
* marginal effect
sum  vot_mar_tot  in 10939
* confidence interval
sum  vtotdo vtotup  in 10939
